package com.all.common.gps;

import java.util.Iterator;

import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.GpsStatus.Listener;
import android.location.LocationManager;
import android.util.Log;

public class GpsStatusListener implements Listener {

	LocationManager mLocationManager ; 
	public GpsStatusListener(LocationManager locationManager)
	{
		mLocationManager = locationManager;
	}
	
	protected final String TAG = this.getClass().getName();
	@SuppressWarnings("unused")
	@Override
	public void onGpsStatusChanged(int event) {
		// TODO Auto-generated method stub
		switch (event) {
		case GpsStatus.GPS_EVENT_FIRST_FIX:
			 Log.i(TAG, "第一次定位");
			break;

		case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
			Log.i(TAG, "卫星状态改变");
			//获取当前状态
            GpsStatus gpsStatus=mLocationManager.getGpsStatus(null);
            //获取卫星颗数的默认最大值
            int maxSatellites = gpsStatus.getMaxSatellites();
            //创建一个迭代器保存所有卫星 
            Iterator<GpsSatellite> iters = gpsStatus.getSatellites().iterator();
            int count = 0;     
            while (iters.hasNext() && count <= maxSatellites) {     
                 GpsSatellite s = iters.next();     
                 count++;     
            }   
			break;
		case GpsStatus.GPS_EVENT_STARTED:
			 Log.i(TAG, "定位启动");
			 /*
			  * 启动GPS定位时
			  * 实现定位的相关业务，如定位服务等
			  * 。。。。
			  * */
			break;
		case GpsStatus.GPS_EVENT_STOPPED:
			 Log.i(TAG, "定位结束");
			 /*
			  * 善有善报GPS定位时
			  * 注销定位的相关业务，如定位服务等
			  * 。。。。
			  * */
			break;
		default:
			
			break;
		}
	}

}
